package com.newly.api.sys.feign;


import com.newly.common.base.constants.ServerUriConstant;
import com.newly.common.base.entity.R;
import com.newly.common.base.entity.sys.tenant.dto.*;
import com.newly.common.base.entity.valid.Insert;
import com.newly.common.base.entity.valid.Update;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @author gjm guan
 * @date 2021/8/19 10:49
 * @desc 租户接口
 */
@Api(tags = "租户api")
@FeignClient(path = ServerUriConstant.NEWLY_SYS_TENANT, name = ServerUriConstant.NEWLY_SYS_SERVICE_NAME)
public interface TenantClient {

    @ApiOperation("创建租户")
    //@PostMapping("/create")
    R create(@NotNull(message = "No request parameters!")
             @Validated(Insert.class) @RequestBody TenantDto tenantDto);

    @ApiOperation("修改租户")
    //@PutMapping("/change")
    R change(@NotNull(message = "No request parameters!")
             @Validated(Update.class) @RequestBody TenantDto tenantDto);

    @ApiOperation("删除租户")
    @DeleteMapping("/deleteByIds")
    R deleteByIds(@NotEmpty(message = "tenantIds can't be empty")
                  @RequestParam("tenantIds") List<Long> tenantIds);

    @ApiOperation("获取当前租户")
    @GetMapping("/queryCurrentTenant")
    R queryCurrentTenant();

    @ApiOperation("获取当前租户")
    @GetMapping("/listInAuth")
    R listInAuth(@NotNull(message = "offset can't be empty") @RequestParam("offset") Integer offset,
                 @NotNull(message = "limit can't be empty") @RequestParam("limit") Integer limit,
                 @RequestParam(value = "domainId", required = false) Integer domainId,
                 @RequestParam(value = "fromTime", required = false) String fromTime,
                 @RequestParam(value = "toTime", required = false) String toTime,
                 @RequestParam(value = "keyword", required = false) String keyword);

    @ApiOperation("创建租户")
    @PostMapping("/create")
    R create(@RequestBody @Valid CreateTenantDto tenantDto);

    @ApiOperation("删除租户")
    @PostMapping("/remove")
    R remove(@RequestBody List<Long> tenantIds);

    @ApiOperation(("导出用户信息表"))
    @GetMapping("/export")
    void export(@RequestParam(value = "keyword", required = false) String keyword,
                HttpServletResponse response);

    @ApiOperation("查询租户列表")
    @GetMapping("/list")
    R list(@RequestParam(value = "offset", defaultValue = "1") Integer offset,
           @RequestParam(value = "limit", defaultValue = "10") Integer limit,
           @RequestParam(value = "keyword", required = false) String keyword);

    @ApiOperation("获取当前租户")
    @GetMapping("/currentTenant")
    R currentTenant();

    @ApiOperation("根据id查询租户")
    @GetMapping("/queryTenantById")
    R queryTenantById(@RequestParam("tenantId") Long tenantId);

    @ApiOperation("获取所有用户名称")
    @GetMapping("/getUserNames")
    R getUserNames();

    @ApiOperation("查询用户名称是否已存在")
    @GetMapping("/repeat")
    R repeat(String userName);

    @ApiOperation("查询邮箱是否已存在")
    @GetMapping("/repeatEmail")
    R repeatEmail(String email);

    @ApiOperation("修改租户信息")
    @PostMapping("/updTenant")
    R updTenant(@RequestBody @Valid UpdTenantDto updTenantDto);

    @ApiOperation("修改密码")
    @PostMapping("/updPassword")
    R updPassword(@RequestBody @Valid UpdPasswordDto updPasswordDto);

    @ApiOperation("通过邮箱修改密码")
    @PostMapping("/updPasswordByEmail")
    R updPasswordByEmail(@RequestBody @Valid UpdPasswordByEmailDto dto);

    @ApiOperation("是否显示弹窗")
    @GetMapping("/isShowWindow")
    R isShowWindow();
}
